const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
    mode: "development",
    entry: {
        index: "./src/component/index.js",
    },
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "[name].js",
    },
    resolve: {
        alias: {
            "@": path.resolve("src"),
        },
    },
    module: {
        rules: [
            { test: /\.txt$/, use: "raw-loader" },
            {
                test: /\.(css|less)$/i,
                use: [
                    // compiles Less to CSS
                    "style-loader",
                    "css-loader",
                    "less-loader",
                ],
            },
            {
                test: /\.(js|jsx)$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env", "@babel/preset-react"],
                    },
                },
            },
            {
                test: /\.(png|jpg|gif|webp)$/,
                loader: "url-loader",
                options: {
                    limit: 8192, // <= 8kb的图片base64内联
                    name: `[name].[ext]`,
                    outputPath: "images/",
                },
            },
            {
                test: /\.(svg|eot|ttf|woff|woff2)$/,
                loader: "url-loader",
                options: {
                    limit: 8192, // <= 8kb的base64内联
                    name: `[name].[ext]`,
                    outputPath: "fonts/",
                },
            },
        ],
    },
    devServer: {
        port: 9000,
        open: true,
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "./index.html"),
        }),
    ],
};
